package frame;

import dao.UserDaoImpl;
import entity.User;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.util.Iterator;
import java.util.Map;

public class UserInfoFrame extends JFrame {
	
	
	public UserInfoFrame() {
		this.setTitle("???????????????");
		this.setSize(400, 300);
		this.setLocation(250, 150);
		init();
		this.setVisible(true);
	}

	public void init() {
		//?????????????,??????????
		Object[] title = {"???", "????", "????", "???", "????"};
		
		//???????????????????????????s
		
		Map<String, User> users = UserDaoImpl.getUsers();
		
		Iterator<Map.Entry<String, User>> iter = users.entrySet().iterator();
		
		Object[][] u = new Object[45][10];
		int i = 0;
		
			while(iter.hasNext()) {
				Map.Entry<String, User> entry=iter.next();
				u[i][0] = entry.getKey();
				u[i][1] = entry.getValue().getName();
				u[i][2] = entry.getValue().getPassword();
				u[i][3] = entry.getValue().getSex();
				u[i][4] = entry.getValue().getCity();
				i++;
			}
		
		JTable t = new JTable(u, title);
		
		this.add(new JScrollPane(t));
	}
}
